var app = getApp();
var api = require('../../api.js');
var util = require('../../utils/util.js');

Page({
  data: {
    pay_money: 0,
    present_money: 0,
  },

  money_change: function(e) {
    var index = e.detail.value;
    this.setData({
      index: index,
    })
  },

  fn_delete: function(e) {
    var id = e.currentTarget.dataset.id;
    wx.showModal({
      title: '删除提示',
      content: '确定删除？',
      showCancel: true,
      cancelText: '取消',
      cancelColor: '',
      confirmText: '删除',
      confirmColor: '',
      success: (res) => {
        if (res.confirm) {
          app.ajax(api.recharge_del, {
            set_id: id,
            rd_session: wx.getStorageSync('rd_session')
          }, (res) => {
            wx.showToast({
              title: '删除成功！',
              icon: 'none',
              image: '',
              duration: 0,
              mask: true,
              success: (res) => {
                this.get_data()
              },
            })

          });

        } else if (res.cancel) {

        }
      },

    })
  },

  formSubmit: function(e) {
    var info = e.detail.value;
    if (info.pay_money == '0') {
      wx.showToast({
        title: '请输入充值金额',
        icon: 'none',
        image: '',
        duration: 0,
        mask: true,
        success: (res) => {
        },
      })
      return false
    } else if (info.present_money == '0') {
      wx.showToast({
        title: '请输入赠送金额',
        icon: 'none',
        image: '',
        duration: 0,
        mask: true,
        success: (res) => {
        },
      })
      return false
    } else {
      app.ajax(api.recharge_set, {
        pay_money: info.pay_money,
        present_money: info.present_money,
        rd_session: wx.getStorageSync('rd_session')
      }, (res) => {
        wx.showToast({
          title: '添加成功',
          icon: 'none',
          image: '',
          duration: 0,
          mask: true,
          success: (res) => {
            this.get_data()
          },
        })
      });
    }

  },
  get_data: function() {
    // 获取信息
    app.ajax(api.recharge_list, {
      rd_session: wx.getStorageSync('rd_session')
    }, (res, err) => {
      var list = res.data.lists;
      this.setData({
        list: list,
      })
    })
  },
  onShow: function() {
    this.get_data()
  }
});